package router

import (
	"github.com/gin-gonic/gin"
	"html/template"
)

func StaticRoute(engine *gin.Engine) {
	engine.Static("/static", "./web/gin/static")

	engine.SetFuncMap(template.FuncMap{
		"safe": func(str string) template.HTML {
			return template.HTML(str)
		},
	})
	engine.LoadHTMLFiles(
		"web/gin/static/html/posts/posts.html",
		"web/gin/static/html/users/users.html",
		"web/gin/static/html/index.html",
		"web/gin/static/html/posts/post2/posts2.html",
		"web/gin/static/html/404.html",
		"web/gin/static/html/upload.html",
		"web/gin/static/html/uploads.html")

	engine.GET("/posts.view", func(c *gin.Context) {
		c.HTML(200, "posts.html", gin.H{
			"title": "hello posts",
		})
	})
	engine.GET("posts2.view", func(c *gin.Context) {
		c.HTML(200, "posts2.html", gin.H{
			"title": "hello posts2",
		})
	})
	engine.GET("/users.view", func(c *gin.Context) {
		c.HTML(200, "users.html", gin.H{
			"title": "hello users",
		})
	})
	engine.GET("/", func(c *gin.Context) {
		c.HTML(200, "index.html", "<a href='https://liwenzhou.com'>李文周的博客</a>")
	})

	engine.GET("/upload.view", func(c *gin.Context) {
		c.HTML(200, "upload.html", nil)
	})
	engine.GET("/uploads.view", func(c *gin.Context) {
		c.HTML(200, "uploads.html", nil)
	})
}
